$(document).ready(function(){
    /***
     *  mainBanner  begin
     ***/
    var mainBanner = '';
    //获取mainBanner列表函数
    function getBannerList(){
        getAjax(`${global.apiUrl}/admin_get_comuunity_service_banner`,function (res) {
            // console.log(res);
            var html = '';
            mainBanner = res;
            for(var i in res){
                html += `
                 <div class="banner-item">
                    <img src="${res[i].banner_img}" alt="" >
                    <div class="eventBox themeColor">
                        <div class="reset" data-toggle="modal" data-target="#myModal" data-id="${res[i].id}" data-type="2">修改</div>
                        <div class="delete" data-id="${res[i].id}" >删除</div>
                    </div>
                 </div>
            `
            }
            html += `
             <div class="banner-add" data-toggle="modal" data-target="#myModal" data-type="1">
                <img src="../../img/community-service/banner_add.png" alt="">
            </div>
        `
            $('#banner-box').html(html);
        },{
            community_id:global.community_id
        })
    }
    //获取mainBanner
    getBannerList();
    //mainBanner修改删除按钮
    $('#banner-box').on('mouseenter','.banner-item',function(){
        $(this).find('.eventBox').css('display','block');
        $(this).find('.eventBox').css('opacity','1');
        // $('.eventBox').css('display','block');
        // $('.eventBox').css('opacity','1');
    })
    $('#banner-box').on('mouseleave','.banner-item',function(){
        $(this).find('.eventBox').css('opacity','.3');
        $(this).find('.eventBox').css('display','none');
    })
    //模态框显示触发事件（添加  修改）
    $('#myModal').on('show.bs.modal',function(event){
        var btnThis = $(event.relatedTarget);
        var modal = $(this);
        // modal.find('.preview-img')
        modal.find('#imgUrl').val('');
        modal.find('.preview-img').html(`<div>图片预览</div>`);
        var type = btnThis.data('type');
        // console.log(type);
        if(type == 1){
            modal.find('#myModalLabel').text('添加BANNER');
            modal.find('#uploadBannerImg').attr('data-type','1');
            modal.find('#bannerId').val('');
            modal.find('#banner_status').val(-1)
        }
        else if(type == 2){
            modal.find('#myModalLabel').text('修改BANNER');
            modal.find('#uploadBannerImg').attr('data-type','2');
            var id = btnThis.data('id');
            // console.log(id,mainBanner);
            modal.find('#bannerId').val(id);
            for(var i in mainBanner){
                if(id == mainBanner[i].id){
                    modal.find('.preview-img').html(`<img src="${mainBanner[i].banner_img}" >`)
                    modal.find('#banner_status').val(mainBanner[i].url_id?mainBanner[i].url_id:-1)
                }
            }
        }
    })
    //删除
    $('#banner-box').on('click','.delete',function(){
        var id = $(this).data('id');
        var r=confirm("是否要删除该轮播图？")
        if (r==true)
        {
            getAjax(`${global.apiUrl}/admin_operation_community_service_banner`,function(res){
                // console.log(res);
                if(res == 1){
                    getBannerList();
                    alert('删除成功！')
                }
            },{
                type:3,
                id:id
            })
        }
    })
    //设置imgUrl值到隐藏的input
    function setImgUrl(res){
        // console.log(res);
        document.getElementById('imgUrl').value = res;
    }
    //上传图片获取图片地址
    imgUpload('fileInput','fileImage',setImgUrl);
    //上传banner图片
    $('#uploadBannerImg').on('click',function(){
        var $imgUrl = $('#imgUrl').val();
        var $bannerId = $('#bannerId').val();
        var type = $('#uploadBannerImg').data('type');
        var urlId = $('#banner_status').val();
        // console.log($imgUrl,$bannerId);
        // console.log(type);
        if($imgUrl == ''){
            alert('请先选择轮播图片，再点击确认！')
        }else{
            getAjax(`${global.apiUrl}/admin_operation_community_service_banner`,function(res){
                if(res == 1){
                    getBannerList();
                    alert('上传成功！');
                    $('#myModal').modal('hide');
                }
            },{
                type:type,
                id:$bannerId,
                banner_img:$imgUrl,
                url_id: urlId,
                community_id: global.community_id
            })
        }
    })
    /***
     *  mainBanner  end
     ***/

    //导航切换
    $('.nav-item').on('click',function(){
        $('.nav-item').removeClass('active');
        $(this).addClass('active');
        var index = $(this).index();
        // console.log(index);
        $('.item-box').css('display','none');
        var itemBox = document.getElementsByClassName('item-box');
        itemBox[index].style.display = 'block';
    })




    /***
    *  家政服务部分 begin
    ***/

    /*** banner ***/
    var homemakingBannerList = ''
    //获取家政服务banner
    function getHomemakingBannerList(){
        getAjax(`${global.apiUrl}/admin_get_comuunity_service_home_shop_banner`,function(res){
            // console.log(res);
            var html = '';
            homemakingBannerList = res;
            for(var i in res){
                html += `
                 <div class="banner-item">
                    <img src="${res[i].banner_img}" alt="" >
                    <div class="eventBox themeColor">
                        <div class="reset" data-toggle="modal" data-target="#homemakingBannerModal" data-id="${res[i].id}" data-type="2">修改</div>
                        <div class="delete" data-id="${res[i].id}" >删除</div>
                    </div>
                 </div>
            `
            }
            html += `
             <div class="banner-add" data-toggle="modal" data-target="#homemakingBannerModal" data-type="1">
                <img src="../../img/community-service/banner_add.png" alt="">
            </div>
        `
            $('#banner-item-box').html(html);
        },{
            community_id:global.community_id
        })
    }
    getHomemakingBannerList();
    $('#banner-item-box').on('mouseenter','.banner-item',function(){
        $(this).find('.eventBox').css('display','block');
        $(this).find('.eventBox').css('opacity','1');
    })
    $('#banner-item-box').on('mouseleave','.banner-item',function(){
        $(this).find('.eventBox').css('opacity','.3');
        $(this).find('.eventBox').css('display','none');
    })
    //modal 触发同时
    $('#homemakingBannerModal').on('show.bs.modal',function(event){
        var btnThis = $(event.relatedTarget);
        var modal = $(this);
        // modal.find('.preview-img')
        modal.find('#homemakingImgUrl').val('');
        modal.find('.preview-img').html(`<div>图片预览</div>`);
        var type = btnThis.data('type');
        console.log(type);
        if(type == 1){
            modal.find('#homingmakingModalLabel').text('添加BANNER');
            modal.find('#uploadHomemakingBannerImg').attr('data-type','1');
            modal.find('#homemakingBannerId').val('');
        }
        else if(type == 2){
            modal.find('#homingmakingModalLabel').text('修改BANNER');
            modal.find('#uploadHomemakingBannerImg').attr('data-type','2');
            var id = btnThis.data('id');
            // console.log(id,mainBanner);
            modal.find('#homemakingBannerId').val(id);
            console.log(homemakingBannerList);
            for(var i in homemakingBannerList){
                if(id == homemakingBannerList[i].id){
                    modal.find('.preview-img').html(`<img src="${homemakingBannerList[i].banner_img}" >`)
                }
            }
        }
    });
    function setHomemakingImgUrl(res){
        document.getElementById('homemakingImgUrl').value = res;
    }
    imgUpload('homemakingInput','homemakingImage',setHomemakingImgUrl);
    //上传，修改
    $('#uploadHomemakingBannerImg').on('click',function(){
        var $imgUrl = $('#homemakingImgUrl').val();
        var $bannerId = $('#homemakingBannerId').val();
        var type = $('#uploadHomemakingBannerImg').data('type');
        console.log($imgUrl,$bannerId);
        console.log(type);
        if($imgUrl == ''){
            alert('请先选择轮播图片，再点击确认！')
        }else{
            getAjax(`${global.apiUrl}/admin_operation_community_service_home_shop_banner`,function(res){
                if(res == 1){
                    getHomemakingBannerList();
                    alert('上传成功！');
                    $('#homemakingBannerModal').modal('hide');
                }
            },{
                type:type,
                id:$bannerId,
                banner_img:$imgUrl,
                community_id: global.community_id
            })
        }
    })
    //删除
    $('#banner-item-box').on('click','.delete',function(){
        var id = $(this).data('id');
        var r=confirm("是否要删除该轮播图？")
        if (r==true)
        {
            getAjax(`${global.apiUrl}/admin_operation_community_service_home_shop_banner`,function(res){
                if(res == 1){
                    getHomemakingBannerList();
                    alert('删除成功！')
                }
            },{
                type:3,
                id:id
            })
        }

    })

    /***  分类 begin   ***/
    var homemakingClass = '';
    function getHomemakingClass(){
        getAjax(`${global.apiUrl}/get_community_service_home_shop_class`,function(res){
            // console.log(res);
            var html = '';
            var addBusinessClass = '';
            var selHtml = '<option value="0">全部</option>';
            homemakingClass = res;
            for(var i in res){
                html += `
                    <div class="class-item">
                    <div class="icon-box">
                        <img src="${res[i].url}" alt="">
                    </div>
                    <div class="icon-text">${res[i].class_name}</div>
                    <div class="class-reset themeColor" data-toggle="modal" data-target="#classModal" data-type="2" data-id="${res[i].id}">修改</div>
                    <div class="class-delete themeColor" data-id="${res[i].id}">删除</div>
                </div>
                `
                selHtml += `
                     <option value="${res[i].id}">${res[i].class_name}</option>
                     
                `
                addBusinessClass += `
                    <div class="checkbox">
                            <label>
                                <input type="checkbox" class="class-checked" value="${res[i].id}"> ${res[i].class_name}
                            </label>
                        </div>
                `
            }
            html += `
                <div class="class-item-add" data-toggle="modal" data-target="#classModal" data-type="1">
                    <div class="icon-box-add">
                        <img src="../../img/community-service/banner_add.png" alt="">
                    </div>
                    <div class="icon-text-add">添加</div>
                </div>
            `
            $('#homemakingClass').html(html);
            $('#homemaking-class-sel ').html(selHtml);
            $('#add-shop-class-box').html(addBusinessClass);

        },{
            community_id:global.community_id
        })
    }
    getHomemakingClass();
    $('.class-box').on('mouseenter','.class-item',function(){
        // console.log(1);
        $(this).css('boxShadow','0 0 8px #f1f1f1');
        $(this).find('.class-reset').css('display','block');
        $(this).find('.class-delete').css('display','block');
    })
    $('.class-box').on('mouseleave','.class-item',function(){
        $(this).css('boxShadow','');
        $(this).find('.class-reset').css('display','none');
        $(this).find('.class-delete').css('display','none');
    })
    $('#classModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        // console.log(type);
        modal.find('#className').val('');
        modal.find('.preview-class-img').html(`<div>图片预览</div>`);
        if(type == 1){
            modal.find('#classModalLabel').text('添加分类');
            modal.find('#uploadClassImg').attr('data-type','1');
            modal.find('#homemakingBannerId').val('');
        }else if(type == 2){
            modal.find('#classModalLabel').text('修改分类');
            modal.find('#uploadClassImg').attr('data-type','2');
            var id = btnThis.data('id');
            console.log(id);
            // console.log(id,mainBanner);
            modal.find('#classItemId').val(id);
            console.log(homemakingClass);
            for(var i in homemakingClass){
                if(id == homemakingClass[i].id){
                    modal.find('.preview-class-img').html(`<img src="${homemakingClass[i].url}" >`);
                    modal.find('#className').val(homemakingClass[i].class_name);
                }
            }
        }
    })
    function setClassImgUrl(res){
        document.getElementById('classImgUrl').value = res;
    }
    //上传图片获取图片地址
    imgUpload('classInput','classImage',setClassImgUrl);
    $('#uploadClassImg').on('click',function(){
        var $classImgUrl = $('#classImgUrl').val();
        var $className = $('#className').val();
        var $classId = $('#classItemId').val();
        var type = $('#uploadClassImg').data('type');
        console.log($classImgUrl,$classId,$className);
        console.log(type);
        if($classImgUrl == ''){
            alert('请先选择轮播图片，再点击确认！')
        }else{
            getAjax(`${global.apiUrl}/operation_community_service_home_shop_class`,function(res){
                if(res == 1){
                    getHomemakingClass();
                    alert('上传成功！');
                    $('#classModal').modal('hide');
                }
            },{
                type:type,
                id:$classId,
                url:$classImgUrl,
                class_name:$className,
                community_id: global.community_id
            })
        }
    })
    $('#homemakingClass').on('click','.class-delete',function(){
        var id = $(this).data('id');
        // console.log(id);
        var f = confirm('删除分类可能造成！软件异常，是否确实删除');
        if(f){
            // console.log(1111);
            getAjax(`${global.apiUrl}/operation_community_service_home_shop_class`,function(res){
                // console.log(res);
                if(res == 1){
                   getHomemakingClass();
                   console.log(res);
                   alert('删除成功！')
               }else if(res == 2){
                   alert('该分类存在商家！不可删除！');
               }

            },{
                type:3,
                id:id
            })
        }
    })

    /***  商户列表  ***/
    //获取商户列表
    var homemakingPageNo = 1,showNum=10;
    var homemakingList = '';
    var homemakingLike = '';
    var homemakingClassId = '';
    function getHomemakingBusiness(p,showNum,$class,like){
        getAjax(`${global.apiUrl}/get_community_service_home_shop`,function(res){
            // console.log(res);

            if(res.list.length == 0){
                $("#page").paging({
                    pageNo:0,
                    totalPage: 0, //总页数
                    totalSize: 0,
                    callback: function(num) {
                        getHomemakingBusiness(num,showNum,$class)
                    }
                });
                var html = `
                        <tr>
                            <td colspan="5" align="center">暂无商家</td>
                        </tr>`
                $('#homemaking-business').html(html);
            }else{
                $("#page").paging({
                    pageNo:p,
                    totalPage: Math.ceil(res.all/showNum), //总页数
                    totalSize: res.all,
                    callback: function(num) {
                        getHomemakingBusiness(num,showNum,$class)
                        homemakingPageNo = num
                    }
                });
                var html = '';
                homemakingList = res.list;
                var list = res.list;
                var className = '';
                for(var i in list){
                    var classList = list[i].all_class;
                    className = [];
                    for(var j in classList){
                        for(var h in homemakingClass){
                            if(homemakingClass[h].id == classList[j].class_id){
                                className.push(homemakingClass[h].class_name);
                                // console.log(className);
                            }
                        }
                    }
                    className = className.toString();
                    html += `
                        <tr>
                            <td class="shop-img">
                                <img src="${list[i].shop_img}" alt="">
                            </td>
                            <td>${list[i].shop_name}</td>
                            <td>${className}</td>
                            <td>${list[i].phone}</td>
                            <td>${list[i].address}</td>
                            <td class="control-td themeColor">
                            <span class="business-reset" data-id="${list[i].id}" data-type="2" data-target="#BusinessModal" data-toggle="modal">修改</span> 
                            <span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">删除</span></td>
                        </tr>
                `
                }
                $('#homemaking-business').html(html);
            }
        },{
            p:p,
            num:showNum,
            community_id:global.community_id,
            class_id:$class,
            like:like
        })
    }
    getHomemakingBusiness(homemakingPageNo,showNum);
    //获取className接口/Api/Communityservice/get_class_name 参数 id

    //服务类别筛选
    $('#homemaking-class-sel').on('change',function(){
        var classId = $(this).children('option:selected').val()
        // console.log(classId);
        homemakingClassId = classId;
        getHomemakingBusiness(homemakingPageNo,showNum,classId,homemakingLike);
    });
    $('#homemaking-search').on('click',function(){
        homemakingLike = $('.search-box').val();
        getHomemakingBusiness(homemakingPageNo,showNum,homemakingClassId,homemakingLike)
    })
    /** 添加商户 **/

   function setBusinessShopImgUrl(res){
       document.getElementById("shop-img-url").value = res;
    }
    var imgs = [];  //商家展示图片
    imgUpload('shop-img-select','shop-img-show',setBusinessShopImgUrl);
    function setContentImgUrl(res){
        if(res.length != 0){
            imgurl = {
                banner_img:res
            } ;
            imgs.push(imgurl)
            console.log(imgs);
            $('#upload-content-img').css('display','none');
        }

    }
    var imgurl;
    var imgArr = imgUploadShow('content-img-select','content-img-show');
    //新图删除
    $('#content-img-show').on('click','.cancle',function(){
        var index = $(this).parent().index();
        imgArr.splice(index,1);
        var contentImgList = document.getElementById('content-img-show');
        // console.log(contentImgList);
        var contentNewImgList = contentImgList.getElementsByClassName('new')[0];
        var contentImgItem = document.getElementsByClassName('content-img-item');
        // console.log(contentImgItem);
        contentNewImgList.removeChild(contentImgItem[index])

    })
    //旧图删除
    $('#content-img-show').on('click','.del',function(){
        var index = $(this).parent().index();
        // console.log(index);
        imgs.splice(index,1);
        var contentImgList = document.getElementById('content-img-show');
        // console.log(contentImgList);
        var contentNewImgList = contentImgList.getElementsByClassName('old')[0];
        var contentImgItem = document.getElementsByClassName('content-old-img-item');
        // console.log(contentImgItem);
        contentNewImgList.removeChild(contentImgItem[index])
        // console.log(imgs);
    })
    $('#upload-content-img').on('click',function(){
        allImgUpload(imgArr,setContentImgUrl)
    });
    $('#BusinessModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        modal.find('#upType').val(type);
        modal.find('#upload-content-img').css('display','none');
        modal.find('#businessId').val('');
        // console.log(type);
        var shopName = modal.find('#shopName');
        shopName.val('');
        var phone = modal.find("#shopPhone");
        phone.val('');
        var address = modal.find("#shopAddress");
        address.val('');
        var lat = modal.find('#shop-address-lat');
        lat.val('');
        var lng = modal.find('#shop-address-lng');
        lng.val('');
        var shopImg = modal.find('#shop-img-url');
        shopImg.val('');
        //商家描述
        var shopDesc = modal.find('#shopDesc');
        shopDesc.val('');
        imgs = [];
        //分类
        var obj = $(".class-checked");
        obj.attr('checked',false);
        modal.find('#content-img-show .old').html('');
        modal.find('#content-img-show .new').html('');//可能存在bug
        modal.find("#shop-img-show").html(`<div>图片预览</div>`);
        //根据type判断是2修改还是1新增
        if(type == 1){
            modal.find('#businessModalLabel').text('新增商家');
        }else if(type == 2){
            modal.find('#businessModalLabel').text('修改商家信息');
            var businessId = btnThis.data('id');
            modal.find('#businessId').val(businessId);
            var businessInfo = '';
            for(var i in homemakingList){
                if(homemakingList[i].id == businessId){
                    businessInfo = homemakingList[i]
                }
            }
            // console.log(businessInfo);
            shopName.val(businessInfo.shop_name);
            address.val(businessInfo.address);
            phone.val(businessInfo.phone);
            lat.val(businessInfo.lat);
            lng.val(businessInfo.lng);
            shopDesc.val(businessInfo.content);
            imgs = businessInfo.head_banner;
            shopImg.val(businessInfo.shop_img);
            modal.find('#shop-img-show').html(`<img src="${businessInfo.shop_img}" />`);
            var head_banner = businessInfo.head_banner;
            // console.log(head_banner);
            var html = '';
            for(var j in head_banner){
                html+= `
                    <div class="content-old-img-item">
                        <img src="${head_banner[j].banner_img}" alt="">
                        <div class="del themeColor">删 除</div>
                     </div>
                `
            }
            modal.find('#content-img-show  .old').html(html);
            obj.each(function(){
                var that = $(this);
                for(var k in businessInfo.all_class){
                    if(that.val() == businessInfo.all_class[k].class_id){
                        // console.log(that.val());
                        that.prop('checked',true);
                    }
                }
            })

        }

    })
    //获取地址
    $('#shopAddress').on('input propertychange',function(){
        var keyword = $(this).val();
        // console.log(keyword == '');
        var region = '天津';
        if(keyword != ''){
            getAjax(`${global.apiUrl}/Api/Url/ceshi`,res =>{
                // console.log(res);
                if(res.status == 0){
                    var html = '';
                    for(var i in res.data){
                        html += `
                        <div class="address-list-item themeColor">
                            <div class="address-title">${res.data[i].title}</div>
                            <div class="address-address">${res.data[i].address}</div>
                            <input type="hidden" class="lat" value="${res.data[i].location.lat}">
                            <input type="hidden" class="lng" value="${res.data[i].location.lng}">
                        </div>
                    `
                    }
                    $('.address-list').html(html);
                }
            },{
                keyword:keyword,
                key:'6VNBZ-2YSC3-UAK3W-YDOS4-QLWCT-OWBXM',
                region:region
            })
        }else{
            $('.address-list').html('');
        }

    });
    $('.address-list').on('click','.address-list-item',function(){
        var address = $(this).find('.address-address').text();
        var title = $(this).find('.address-title').text();
        var lat = $(this).find('.lat').val();
        var lng = $(this).find('.lng').val();
        $('.address-list').html('');
        $('#shopAddress').val(`${title} (${address})`)
        $('#shop-address-lat').val(lat)
        $('#shop-address-lng').val(lng)
    })
    /** 添加 修改 **/
    $('#addShop').on('click',function(){

        //获取选择的类别
        var obj = document.getElementsByClassName("class-checked");
        var check_class = new Array();
        for(k in obj){
            if(obj[k].checked)
                check_class.push(obj[k].value);
        }
        var subContent = [];
        for(var i in check_class){
            for(var j in homemakingClass){
                if(check_class[i] == homemakingClass[j].id){
                    subContent.push(homemakingClass[j].class_name)
                }
            }
        }
        subContent = subContent.toString();
        //获取名称
        var shopName = $('#shopName').val();
        //地址及其lat  lng
        var address = $('#shopAddress').val();
        var lat = $('#shop-address-lat').val();
        var lng = $('#shop-address-lng').val();
        //商家电话
        var phone = $('#shopPhone').val();
        //获取缩略图
        var shopImg = $('#shop-img-url').val();
        //获取商家图集
        var headBanner = JSON.stringify(imgs);
        //商家描述
        var shopDesc = $('#shopDesc').val();
        console.log(check_class,shopName,shopImg,address,lat,lng,phone,headBanner,subContent,shopDesc);
        //数据
        if(shopName == ''||phone == ''||address==''||shopImg==''||subContent==''||headBanner==''||shopDesc==""){
            alert('请将信息填写完整！')
        }else{
            var type = $("#upType").val();
            console.log('type:',type);
            var id = $("#businessId").val();
            var text = '';
            if(type == 2){
                // id = $(this).data('id');
                text = '商家信息，修改成功！';
            }else if(type == 1){
                text = '新的商家，添加成功！';
            }
            console.log('businessId',id);
            var data = {
                "shop_name":shopName,
                "phone":phone,
                "address":address,
                "shop_img":shopImg,
                "sub_content":subContent,
                "head_banner":headBanner,
                "content":shopDesc,
                "community_id":global.community_id,
                "lat":lat,
                "lng":lng
            }
            data = JSON.stringify(data);
            // console.log(data);
            check_class = JSON.stringify(check_class);
            $.ajax({
                url:`${global.apiUrl}/operation_community_service_home_shop`,
                type:'GET',
                data:{
                    type:type,
                    shop_content:data,
                    class_id:check_class,
                    id:id
                },
                success(res){
                    // console.log(res);
                    if(res == 1){
                        alert(text);
                        $('#BusinessModal').modal('hide');
                        getHomemakingBusiness(homemakingPageNo,showNum);
                    }
                },
                error(res){
                    console.log(res);
                }
            })

        }


    })
    /** 删除 **/
    $('#homemaking-business').on('click','.business-delete',function(){
        var businessId = $(this).data('id');
        var f = confirm('是否删除该商户');
        if(f){
            getAjax(`${global.apiUrl}/operation_community_service_home_shop`,function(res){
                console.log(res);
                if(res == 1){
                    alert('商户删除成功！');
                    getHomemakingBusiness(homemakingPageNo,showNum);
                }
            },{
                type:3,
                id:businessId
            })
        }

    })

    /***
     * 家政服务部分 end
     ***/




    /***
     * 社区商城 begin
     ***/
    var shopBannerList = ''
    //获取家政服务banner
    function getShopBannerList(){
        getAjax(`${global.apiUrl}/get_community_service_shop_banner`,function(res){
            // console.log(res);
            var html = '';
            shopBannerList = res;
            for(var i in res){
                html += `
                 <div class="banner-item">
                    <img src="${res[i].banner_img}" alt="" >
                    <div class="eventBox themeColor">
                        <div class="reset" data-toggle="modal" data-target="#shopBannerModal" data-id="${res[i].id}" data-type="2">修改</div>
                        <div class="delete" data-id="${res[i].id}" >删除</div>
                    </div>
                 </div>
            `
            }
            html += `
             <div class="banner-add" data-toggle="modal" data-target="#shopBannerModal" data-type="1">
                <img src="../../img/community-service/banner_add.png" alt="">
            </div>
        `
            $('#banner-shop-box').html(html);
        },{
            community_id:global.community_id
        })
    }
    getShopBannerList();
    $('#banner-shop-box').on('mouseenter','.banner-item',function(){
        $(this).find('.eventBox').css('display','block');
        $(this).find('.eventBox').css('opacity','1');
    })
    $('#banner-shop-box').on('mouseleave','.banner-item',function(){
        $(this).find('.eventBox').css('opacity','.3');
        $(this).find('.eventBox').css('display','none');
    })
    $('#shopBannerModal').on('show.bs.modal',function(event){
        var btnThis = $(event.relatedTarget);
        var modal = $(this);
        // modal.find('.preview-img')
        modal.find('#shopImgUrl').val('');
        modal.find('.preview-img').html(`<div>图片预览</div>`);
        var type = btnThis.data('type');
        console.log(type);
        if(type == 1){
            modal.find('#shopModalLabel').text('添加商城BANNER');
            modal.find('#uploadShopBannerImg').attr('data-type','1');
            modal.find('#shopBannerId').val('');
        }
        else if(type == 2){
            modal.find('#shopModalLabel').text('修改商城BANNER');
            modal.find('#uploadShopBannerImg').attr('data-type','2');
            var id = btnThis.data('id');
            // console.log(id,mainBanner);
            modal.find('#shopBannerId').val(id);
            console.log(shopBannerList);
            for(var i in shopBannerList){
                if(id == shopBannerList[i].id){
                    modal.find('.preview-img').html(`<img src="${shopBannerList[i].banner_img}" >`)
                }
            }
        }
    });
    function setShopImgUrl(res){
        document.getElementById('shopImgUrl').value = res;
    }
    imgUpload('shopInput','shopImage',setShopImgUrl);
    //上传，修改
    $('#uploadShopBannerImg').on('click',function(){
        var $imgUrl = $('#shopImgUrl').val();
        var $bannerId = $('#shopBannerId').val();
        var type = $('#uploadShopBannerImg').data('type');
        console.log($imgUrl,$bannerId);
        console.log(type);
        if($imgUrl == ''){
            alert('请先选择轮播图片，再点击确认！')
        }else{
            getAjax(`${global.apiUrl}/admin_operation_community_service_shop_banner`,function(res){
                if(res == 1){
                    getShopBannerList();
                    alert('上传成功！');
                    $('#shopBannerModal').modal('hide');
                }
            },{
                type:type,
                id:$bannerId,
                banner_img:$imgUrl,
                community_id: global.community_id
            })
        }
    })
    //删除
    $('#banner-shop-box').on('click','.delete',function(){
        var id = $(this).data('id');
        var r=confirm("是否要删除该轮播图？")
        if (r==true)
        {
            getAjax(`${global.apiUrl}/admin_operation_community_service_shop_banner`,function(res){
                if(res == 1){
                    getShopBannerList();
                    alert('删除成功！')
                }
            },{
                type:3,
                id:id
            })
        }

    })

    /** 添加商家 **/
    var communityShopPage = 1;
    $('#addShopBusiness').on('click',function(){
        var businessName = $('#businessName').val();
        var businessNum = $('#businessNum').val();
        var businessPwd = $('#businessPwd').val();
        var businessPhone = $('#businessPhone').val();
        var cityRebate = $('#cityRebate').val();
        var areaRebate = $('#cityRebate').val();
        var groupRebate = $('#cityRebate').val();
        var user_content = {
            user_name:businessNum,
            user_pwd:businessPwd,
            type:3
        }
        var content = {
            shop_name:businessName,
            community_id:global.community_id,
            shi_lv:cityRebate/100,
            qu_lv:areaRebate/100,
            als_lv:groupRebate/100,
            type_level:global.community_type

            // shi_user_id:1,
            // qu_user_id:1
        }
        user_content = JSON.stringify( user_content);
        content = JSON.stringify(content);
        console.log(businessName, businessNum, businessPwd);
        if(!businessNum||!businessName||!businessPwd||!businessPhone||!cityRebate||!areaRebate||!groupRebate){
            alert('请填写完整的商家信息！');
        }else{
        console.log(11);
        getAjax(`${global.apiUrl}/admin_add_community_service_shop`,function(res){
            //console.log(res);//4手机号错误 2用户名重复
            if(res == 1){
                alert('超市添加成功！');
                $('#shopBusinessModal').modal('hide');
                getShopList(communityShopPage,showNum);
            }
        },{
            phone:businessPhone,
            user_content:user_content,
            content:content
        })
        }
    })
    /** 获取商家列表 **/
    function getShopList(p,num){
        getAjax(`${global.apiUrl}/get_community_service_shop`,function(res){
            console.log(res);
            if(res.list.length == 0){
                $('#community-shop-page').paging({
                    pageNo:0,
                    totalPage: 0, //总页数
                    totalSize: 0,
                    callback: function(num) {
                        getShopList(num,showNum)
                    }
                })
            }else{
                $('#community-shop-page').paging({
                    pageNo:communityShopPage,
                    totalPage: Math.ceil(res.count/showNum), //总页数
                    totalSize: res.count,
                    callback: function(num) {
                        getShopList(num,showNum)
                    }
                })
                var html = '';
                var list = res.list;
                for(var i in list){
                    html += `
                           <tr>
                            <td class="shop-img">
                                <img src="${list[i].head_img}" alt="">
                            </td>
                            <td>${list[i].shop_name}</td>
                            <td>${list[i].open_time==null?" ":list[i].open_time}-${list[i].close_time==null?" ":list[i].close_time}</td>
                            <td>${list[i].up_pay==null?0:list[i].up_pay}</td>
                            <td>${list[i].address ==null?' ':list[i].address}</td>
                            <td class="control-td themeColor">
                            <span class="business-reset" data-id="${list[i].id}" data-type="2" data-target="#BusinessModal" data-toggle="modal">查看信息</span> 
                            <span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">冻结</span>
                            <span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">查看订单</span>
                            <span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">重置密码</span></td>
                        </tr>
                    `
                }
                $('#community-shop-list').html(html)
            }
        },{
            type:1,//塞选条件
            community_id:global.community_id,
            p:1,
            num:showNum
        })
    }
    getShopList(communityShopPage,showNum);
    /***
     * 社区商城 end
     ***/


    /***
     *  二手商城 begin
     ***/
    //获取分类
    var secondHandClass = '';
    function getsecondHandClass(){
        getAjax(`${global.apiUrl}/get_old_product_class`,function(res){
            // console.log(res);
            var html = '';
            var selHtml = '<option value="0">全部</option>';
            secondHandClass = res;
            for(var i in res){
                html += `
                    <div class="class-item">
                    <div class="icon-box">
                        <img src="${res[i].ico}" alt="">
                    </div>
                    <div class="icon-text">${res[i].class_name}</div>
                    <div class="class-reset themeColor" data-toggle="modal" data-target="#secondHandClassModal" data-type="2" data-id="${res[i].id}">修改</div>
                    <div class="class-delete themeColor" data-id="${res[i].id}">删除</div>
                </div>
                `
                selHtml += `
                     <option value="${res[i].id}">${res[i].class_name}</option>
                     
                `
            }
            html += `
                <div class="class-item-add" data-toggle="modal" data-target="#secondHandClassModal" data-type="1">
                    <div class="icon-box-add">
                        <img src="../../img/community-service/banner_add.png" alt="">
                    </div>
                    <div class="icon-text-add">添加</div>
                </div>
            `
            $('#secondHandClass').html(html);
            $('#secondHand-class-sel').html(selHtml);

        },{
            community_id:global.community_id
        })
    }
    getsecondHandClass();
    $('#secondHandClass').on('mouseenter','.class-item',function(){
        // console.log(1);
        $(this).css('boxShadow','0 0 8px #f1f1f1');
        $(this).find('.class-reset').css('display','block');
        $(this).find('.class-delete').css('display','block');
    })
    $('#secondHandClass').on('mouseleave','.class-item',function(){
        $(this).css('boxShadow','');
        $(this).find('.class-reset').css('display','none');
        $(this).find('.class-delete').css('display','none');
    })
    $('#secondHandClassModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        // console.log(type);
        modal.find('#secondHandClassName').val('');
        modal.find('.preview-class-img').html(`<div>图片预览</div>`);
        if(type == 1){
            modal.find('#secondHandClassModalLabel').text('添加二手商品分类');
            modal.find('#uploadsecondHandClassImg').attr('data-type','1');
            modal.find('#secondHandClassItemId').val('');
        }else if(type == 2){
            modal.find('#secondHandClassModalLabel').text('修改二手商品分类');
            modal.find('#uploadsecondHandClassImg').attr('data-type','2');
            var id = btnThis.data('id');
            console.log(id);
            // console.log(id,mainBanner);
            modal.find('#secondHandClassItemId').val(id);
            console.log(secondHandClass);
            for(var i in secondHandClass){
                if(id == secondHandClass[i].id){
                    modal.find('.preview-class-img').html(`<img src="${secondHandClass[i].url}" >`);
                    modal.find('#secondHandClassName').val(secondHandClass[i].class_name);
                }
            }
        }
    })
    function setsecondHandClassImgUrl(res){
        document.getElementById('secondHandClassImgUrl').value = res;
    }
    //上传图片获取图片地址
    imgUpload('secondHandClassInput','secondHandClassImage',setsecondHandClassImgUrl);
    $('#uploadsecondHandClassImg').on('click',function(){
        var $classImgUrl = $('#secondHandClassImgUrl').val();
        var $className = $('#secondHandClassName').val();
        var $classId = $('#secondHandClassItemId').val();
        var type = $('#uploadsecondHandClassImg').data('type');
        console.log($classImgUrl,$classId,$className);
        console.log(type);
        var pro = {
            id:$classId,
            ico:$classImgUrl,
            class_name:$className,
            community_id: global.community_id
        }
        pro = JSON.stringify(pro);
        if($classImgUrl == ''){
            alert('请先选图片，再点击确认！')
        }else{
            getAjax(`${global.apiUrl}/admin_operation_community_service_old_product_class`,function(res){
                if(res == 1){
                    getsecondHandClass();
                    alert('上传成功！');
                    $('#secondHandClassModal').modal('hide');
                }
            },{
                type:type,
                pro:pro
            })
        }
    })
    $('#secondHandClass').on('click','.class-delete',function(){
        var id = $(this).data('id');
        // console.log(id);
        var f = confirm('删除分类可能造成！软件异常，是否确实删除');
        if(f){
            // console.log(1111);
            getAjax(`${global.apiUrl}/admin_operation_community_service_old_product_class`,function(res){
                // console.log(res);
                if(res == 1){
                    getsecondHandClass();
                    console.log(res);
                    alert('删除成功！')
                }else if(res == 2){
                    alert('该分类存在商品！不可删除！');
                }

            },{
                type:3,
                id:id
            })
        }
    })
    //获取商品列表
    var secondHandStatus = 1;
    var secondHandPage = 1;
    var secondHandClassId = 0;
    var secondHandlike = '';
    function getSecondHandProduct(p,showNum,status,classId,keyword){
        console.log(p, showNum, status, classId, keyword);
        getAjax(`${global.apiUrl}/get_old_product_all`,res=>{
            var html = '';
            if(res.list.length == 0){

                $('#secondHand-page').paging({
                    pageNo:0,
                    totalPage:0,
                    totalSize:0,
                    callback(num){
                        getSecondHandProduct(num,showNum,status)
                    }
                })
                html = `<tr>
                              <td colspan="8" align="center">暂无商品</td>
                        </tr>`
            }else{
                $('#secondHand-page').paging({
                    pageNo:p,
                    totalPage:Math.ceil(res.count/showNum),
                    totalSize:res.count,
                    callback(num){
                        getSecondHandProduct(num,showNum,status,classId,keyword);
                        secondHandPage = num;
                    }
                })
                var list = res.list;
                for(var i in list){
                    var className = '';
                    for(var j in secondHandClass){
                        if(list[i].class_id == secondHandClass[j].id){
                            className = secondHandClass[j].class_name
                        }
                    }
                    // 0为未审核 1为通过 2拒绝

                    if(status == 0){
                        html += `
                          <tr>
                            <td class="shop-img">
                                <img src="${list[i].head_img}" alt="">
                            </td>
                            <td>${list[i].product_name}</td>
                            <td>${className}</td>
                            <td>${list[i].price}</td>
                            <td>${list[i].phone}</td>
                            
                            <td class="control-td themeColor">                         
                            <span class="business-reset" data-id="${list[i].id}" data-status="0" data-target="#secondHandProductModal" data-toggle="modal">审核</span> 
                            <!--<span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">查看详情</span></td>-->
                        </tr>
                        `
                    }else{
                        html += `
                          <tr>
                            <td class="shop-img">
                                <img src="${list[i].head_img}" alt="">
                            </td>
                            <td>${list[i].product_name}</td>
                            <td>${className}</td>
                            <td>${list[i].price}</td>
                            <td>${list[i].phone}</td>
                            
                            <td class="control-td themeColor">                         
                            <span class="business-reset" data-id="${list[i].id}" data-status="1" data-target="#secondHandProductModal" data-toggle="modal">查看</span> 
                            <!--<span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">删除</span></td>-->
                            </tr>
                        `
                    }

                }

            }
            $('#secondHand-product').html(html);

        },{
            p:p,
            num:showNum,
            status:status,
            class_id:classId,
            like:keyword,
            community_id:global.community_id
        })
    }
    getSecondHandProduct(secondHandPage,showNum,secondHandStatus,secondHandClassId,secondHandlike);
    $('#secondHand-list-sel').on('change',function(){
        secondHandStatus = $(this).children('option:selected').val();
        getSecondHandProduct(secondHandPage,showNum,secondHandStatus,secondHandClassId,secondHandlike);
    })
    $('#secondHand-class-sel').on('change',function(){
        secondHandClassId = $(this).children('option:selected').val();
        getSecondHandProduct(secondHandPage,showNum,secondHandStatus,secondHandClassId,secondHandlike);
    })
    $('#secondHand-search').on('click',()=>{
        secondHandlike = $('#secondHandKeyword').val();
        getSecondHandProduct(secondHandPage,showNum,secondHandStatus,secondHandClassId,secondHandlike);

    })
    $('#secondHandProductModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btn = $(event.relatedTarget);
        var status = btn.data('status');
        var id = btn.data('id');
        console.log('id:'+id,'status'+status);
        getAjax(`${global.apiUrl}/get_old_product_content`,res=>{
            console.log(res);
            var modalFoot = '';
            if(status == 0){
                modalFoot = `
                    <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                    <button type="button" class="btn themeBgColor" id="product_reject">拒绝发布</button>
                    <button type="button" class="btn themeBgColor " id="product_pass">通过审核</button>
                `
            }
            var htm ="";
            for(var i in res.content_img){
                htm += `
                    <img src='${res.content_img[i].img}' >
                `
            }
            var html = `
                 <div class="margin15">商品名称：${res.product_name}</div>
                 <input type="hidden" id='product_id' value="${res.id}">
                <div class="margin15">商品价格：${res.price}（元）</div>
                <div class="margin15">卖家电话：${res.phone}</div>
                <div class="margin15">
                    <div>商品缩略图:</div>
                    <div class="img-box">
                        <img src="${res.head_img}" alt="">
                    </div>
                </div>
                <div class="margin15">
                    <div>商品详情图:</div>
                    <div class="img-box">
                        ${htm}
                    </div>
                </div>
                <div class="margin15">
                    <div class="margin15" style="margin-top: 0">商品描述：</div>
                    <div>${res.sub_content}</div>
                </div>
            `
            modal.find('#product-info').html(html);
            modal.find('#checkout').html(modalFoot);
        },{
            id:id
        })

    })
    function setProductStatus(id,status){
        getAjax(`${global.apiUrl}/admin_approval_community_service_old_product`,res=>{
            console.log(res);
            if(res == 1){
                alert('审核完成！');
                $('#secondHandProductModal').modal('hide');
                getSecondHandProduct(secondHandPage,showNum,secondHandStatus,secondHandClassId,secondHandlike)
            }
        },{
            id:id,
            status:status
        })
    }
    $('#checkout').on('click','#product_pass',function(){
        var id = $('#product_id').val();
        setProductStatus(id,1)
    })
    $('#checkout').on('click','#product_reject',()=>{
        var id = $('#product_id').val();
        setProductStatus(id,2)
    })
    /***
     *  二手商城 end
     ***/





    /***
     * 健康服务 begin
     ***/
    /*** banner ***/
    var healthServiceBannerList = ''
    //获取健康服务banner
    function getHealthBannerList(){
        getAjax(`${global.apiUrl}/get_community_service_up_home_shop_banner`,function(res){
            // console.log(res);
            var html = '';
            healthServiceBannerList = res;
            for(var i in res){
                html += `
                 <div class="banner-item">
                    <img src="${res[i].banner_img}" alt="" >
                    <div class="eventBox themeColor">
                        <div class="reset" data-toggle="modal" data-target="#healthBannerModal" data-id="${res[i].id}" data-type="2">修改</div>
                        <div class="delete" data-id="${res[i].id}" >删除</div>
                    </div>
                 </div>
            `
            }
            html += `
             <div class="banner-add" data-toggle="modal" data-target="#healthBannerModal" data-type="1">
                <img src="../../img/community-service/banner_add.png" alt="">
            </div>
        `
            $('#health-banner-item-box').html(html);
        },{
            community_id:global.community_id
        })
    }
    getHealthBannerList();
    $('#health-banner-item-box').on('mouseenter','.banner-item',function(){
        $(this).find('.eventBox').css('display','block');
        $(this).find('.eventBox').css('opacity','1');
    })
    $('#health-banner-item-box').on('mouseleave','.banner-item',function(){
        $(this).find('.eventBox').css('opacity','.3');
        $(this).find('.eventBox').css('display','none');
    })
    //modal 触发同时
    $('#healthBannerModal').on('show.bs.modal',function(event){
        var btnThis = $(event.relatedTarget);
        var modal = $(this);
        // modal.find('.preview-img')
        modal.find('#healthBannerImgUrl').val('');
        modal.find('.preview-img').html(`<div>图片预览</div>`);
        var type = btnThis.data('type');
        console.log(type);
        modal.find('#health-banner-type').val(type);
        if(type == 1){
            modal.find('#healthBannerModalLabel').text('添加BANNER');
            modal.find('#healthBannerId').val('');
        }
        else if(type == 2){
            modal.find('#healthBannerModalLabel').text('修改BANNER');
            // modal.find('#uploadHealthBannerImg').attr('data-type','2');
            var id = btnThis.data('id');
            // console.log(id,mainBanner);
            modal.find('#healthBannerId').val(id);
            console.log(healthServiceBannerList);
            for(var i in healthServiceBannerList){
                if(id == healthServiceBannerList[i].id){
                    modal.find('.preview-img').html(`<img src="${healthServiceBannerList[i].banner_img}" >`)
                }
            }
        }
    });
    function setHealthBannerImgUrl(res){
        document.getElementById('healthBannerImgUrl').value = res;
    }
    imgUpload('healthBannerInput','healthBannerImage',setHealthBannerImgUrl);
    //上传，修改
    $('#uploadHealthBannerImg').on('click',function(){
        var $imgUrl = $('#healthBannerImgUrl').val();
        var $bannerId = $('#healthBannerId').val();
        var type = $('#health-banner-type').val();
        console.log($imgUrl,$bannerId);
        console.log(type);
        if($imgUrl == ''){
            alert('请先选择轮播图片，再点击确认！')
        }else{
            getAjax(`${global.apiUrl}/admin_operation_community_service_up_home_shop_banner`,function(res){
                console.log(res);
                if(res == 1){
                    getHealthBannerList();
                    alert('上传成功！');
                    $('#healthBannerModal').modal('hide');
                }
            },{
                type:type,
                id:$bannerId,
                banner_img:$imgUrl,
                community_id: global.community_id
            })
        }
    })
    //删除
    $('#health-banner-item-box').on('click','.delete',function(){
        var id = $(this).data('id');
        var r = confirm("是否要删除该轮播图？")
        if (r == true)
        {
            getAjax(`${global.apiUrl}/admin_operation_community_service_up_home_shop_banner`,function(res){
                if(res == 1){
                    getHealthBannerList();
                    alert('删除成功！')
                }
            },{
                type:3,
                id:id
            })
        }

    })

    /***  分类 begin   ***/
    var healthServiceClass = '';
    function getHealthServiceClass(){
        getAjax(`${global.apiUrl}/get_community_service_up_home_shop_class`,function(res){
            // console.log(res);
            var html = '';
            var addBusinessClass = '';
            var selHtml = '<option value="0">全部</option>';
            healthServiceClass = res;
            for(var i in res){
                html += `
                    <div class="class-item">
                    <div class="icon-box">
                        <img src="${res[i].url}" alt="">
                    </div>
                    <div class="icon-text">${res[i].class_name}</div>
                    <div class="class-reset themeColor" data-toggle="modal" data-target="#healthClassModal" data-type="2" data-id="${res[i].id}">修改</div>
                    <div class="class-delete themeColor" data-id="${res[i].id}">删除</div>
                </div>
                `
                selHtml += `
                     <option value="${res[i].id}">${res[i].class_name}</option>
                     
                `
                addBusinessClass += `
                    <div class="checkbox">
                            <label>
                                <input type="checkbox" class="health-class-checked" value="${res[i].id}"> ${res[i].class_name}
                            </label>
                        </div>
                `
            }
            html += `
                <div class="class-item-add" data-toggle="modal" data-target="#healthClassModal" data-type="1">
                    <div class="icon-box-add">
                        <img src="../../img/community-service/banner_add.png" alt="">
                    </div>
                    <div class="icon-text-add">添加</div>
                </div>
            `
            $('#healthClass').html(html);
            $('#health-class-sel ').html(selHtml);
            $('#add-health-shop-class-box').html(addBusinessClass);

        },{
            community_id:global.community_id
        })
    }
    getHealthServiceClass();
    $('#healthClass').on('mouseenter','.class-item',function(){
        // console.log(1);
        $(this).css('boxShadow','0 0 8px #f1f1f1');
        $(this).find('.class-reset').css('display','block');
        $(this).find('.class-delete').css('display','block');
    })
    $('#healthClass').on('mouseleave','.class-item',function(){
        $(this).css('boxShadow','');
        $(this).find('.class-reset').css('display','none');
        $(this).find('.class-delete').css('display','none');
    })
    $('#healthClassModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        // console.log(type);
        modal.find('#healthClassName').val('');
        modal.find('.preview-class-img').html(`<div>图片预览</div>`);
        modal.find('#healthClassType').val(type);

        if(type == 1){
            modal.find('#healthClassModalLabel').text('添加分类');
            modal.find('#healthClassItemId').val('');
        }else if(type == 2){
            modal.find('#healthClassModalLabel').text('修改分类');
            // modal.find('#uploadClassImg').attr('data-type','2');
            var id = btnThis.data('id');
            console.log(id);
            // console.log(id,mainBanner);
            modal.find('#healthClassItemId').val(id);
            console.log(healthServiceClass);
            for(var i in healthServiceClass){
                if(id == healthServiceClass[i].id){
                    modal.find('.preview-class-img').html(`<img src="${healthServiceClass[i].url}" >`);
                    modal.find('#healthClassName').val(healthServiceClass[i].class_name);
                }
            }
        }
    })
    function setHealthServiceClassImgUrl(res){
        document.getElementById('healthClassImgUrl').value = res;
    }
    //上传图片获取图片地址
    imgUpload('healthClassInput','healthClassImage',setHealthServiceClassImgUrl);
    $('#uploadHealthClassImg').on('click',function(){
        var $classImgUrl = $('#healthClassImgUrl').val();
        var $className = $('#healthClassName').val();
        var $classId = $('#healthClassItemId').val();
        var type = $('#healthClassType').val();
        // console.log($classImgUrl,$classId,$className);
        // console.log(type);
        if($classImgUrl == ''){
            alert('请先选择轮播图片，再点击确认！')
        }else{
            getAjax(`${global.apiUrl}/admin_operation_community_service_up_home_shop_class`,function(res){
                // console.log(res);
                if(res == 1){
                    getHealthServiceClass();
                    alert('上传成功！');
                    $('#healthClassModal').modal('hide');
                }
            },{
                type:type,
                id:$classId,
                url:$classImgUrl,
                class_name:$className,
                community_id: global.community_id
            })
        }
    })
    $('#healthClass').on('click','.class-delete',function(){
        var id = $(this).data('id');
        // console.log(id);
        var f = confirm('删除分类可能造成！软件异常，是否确实删除');
        if(f){
            // console.log(1111);
            getAjax(`${global.apiUrl}/admin_operation_community_service_up_home_shop_class`,function(res){
                // console.log(res);
                if(res == 1){
                    getHealthServiceClass();
                    console.log(res);
                    alert('删除成功！')
                }else if(res == 2){
                    alert('该分类存在商家！不可删除！');
                }

            },{
                type:3,
                id:id
            })
        }
    })

    /***  商户列表  ***/
        //获取商户列表
    var healthPageNo = 1;
    var healthList = '';
    var healthLike = '';
    var healthClassId = '';
    function getHealthBusiness(p,showNum,$class,like){
        getAjax(`${global.apiUrl}/get_community_service_up_home_shop`,function(res){
            // console.log(res);
            if(res.list.length == 0){
                $("#health-page").paging({
                    pageNo:0,
                    totalPage: 0, //总页数
                    totalSize: 0,
                    callback: function(num) {
                        getHealthBusiness(num,showNum,$class)
                    }
                });
                var html = `
                        <tr>
                            <td colspan="5" align="center">暂无商家</td>
                        </tr>`
                $('#health-service-business').html(html);
            }else{
                $("#health-page").paging({
                    pageNo:p,
                    totalPage: Math.ceil(res.count/showNum), //总页数
                    totalSize: res.count,
                    callback: function(num) {
                        getHealthBusiness(num,showNum,$class)
                        healthPageNo = num
                    }
                });
                var html = '';
                healthList = res.list;
                var list = res.list;
                var className = '';
                for(var i in list){
                    var classList = list[i].class_id;
                    className = [];
                    for(var j in classList){
                        // console.log(healthServiceClass);
                        for(var h in healthServiceClass){
                            if(healthServiceClass[h].id == classList[j].class_id){
                                className.push(healthServiceClass[h].class_name);
                                // console.log(className);
                            }
                        }
                    }
                    className = className.toString();
                    // console.log(className);
                    html += `
                        <tr>
                            <td class="shop-img">
                                <img src="${list[i].shop_img}" alt="">
                            </td>
                            <td>${list[i].shop_name}</td>
                            <td>${className}</td>
                            <td>${list[i].phone}</td>
                            <td>${list[i].address}</td>
                            <td class="control-td themeColor">
                            <span class="business-reset" data-id="${list[i].id}" data-type="2" data-target="#healthBusinessModal" data-toggle="modal">修改</span> 
                            <span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">删除</span></td>
                        </tr>
                `
                }
                $('#health-service-business').html(html);
            }
        },{
            p:p,
            num:showNum,
            community_id:global.community_id,
            class_id:$class,
            like:like
        })
    }
    getHealthBusiness(healthPageNo,showNum);
    //获取className接口/Api/Communityservice/get_class_name 参数 id

    //服务类别筛选
    $('#health-class-sel').on('change',function(){
        var classId = $(this).children('option:selected').val()
        // console.log(classId);
        healthClassId = classId;
        getHealthBusiness(healthPageNo,showNum,classId,healthLike);
    });
    $('#health-search').on('click',function(){
        healthLike = $('#health-search-input').val();
        getHealthBusiness(healthPageNo,showNum,healthClassId,healthLike)
    })
    /** 添加商户 **/
    function setHealthShopImgUrl(res){
        console.log(res);
        document.getElementById('health-shop-img-url').value = res;
    }
    var healthImgs = [];  //商家展示图片
    imgUpload('health-shop-img-select','health-shop-img-show',setHealthShopImgUrl);
    function setHealthContentImgUrl(res){
        if(res.length != 0){
            healthImgurl = {
                banner_img:res
            } ;
            healthImgs.push(healthImgurl)
            console.log(healthImgs);
            $('#upload-health-content-img').css('display','none');
        }

    }
    var healthImgurl;
    var healthImgArr = imgUploadShow('health-content-img-select','health-content-img-show');
    //新图删除
    $('#health-content-img-show').on('click','.cancle',function(){
        var index = $(this).parent().index();
        healthImgArr.splice(index,1);
        var contentImgList = document.getElementById('health-content-img-show');
        // console.log(contentImgList);
        var contentNewImgList = contentImgList.getElementsByClassName('new')[0];
        var contentImgItem = contentNewImgList.getElementsByClassName('content-img-item');
        // console.log(contentImgItem);
        contentNewImgList.removeChild(contentImgItem[index])

    })
    //旧图删除
    $('#health-content-img-show').on('click','.del',function(){
        var index = $(this).parent().index();
        // console.log(index);
        healthImgs.splice(index,1);
        var contentImgList = document.getElementById('health-content-img-show');
        // console.log(contentImgList);
        var contentOldImgList = contentImgList.getElementsByClassName('old')[0];
        var contentImgItem = contentOldImgList.getElementsByClassName('content-old-img-item');
        // console.log(contentImgItem);
        contentOldImgList.removeChild(contentImgItem[index])
        // console.log(imgs);
    })
    $('#upload-health-content-img').on('click',function(){
        allImgUpload(healthImgArr,setHealthContentImgUrl)
    });
    $('#healthBusinessModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        console.log(type);
        modal.find('#health-upType').val(type);
        modal.find('#upload-health-content-img').css('display','block');
        modal.find('#health-businessId').val('');
        // console.log(type);
        var shopName = modal.find('#healthShopName');
        shopName.val('');
        var phone = modal.find("#healthShopPhone");
        phone.val('');
        var address = modal.find("#healthShopAddress");
        address.val('');
        var lat = modal.find('#health-shop-address-lat');
        lat.val('');
        var lng = modal.find('#health-shop-address-lng');
        lng.val('');
        var shopImg = modal.find('#health-shop-img-url');
        shopImg.val('');
        //商家描述
        var shopDesc = modal.find('#health-shopDesc');
        shopDesc.val('');
        //分类
        var obj = $(".health-class-checked");
        obj.attr('checked',false);
        modal.find('#health-content-img-show .old').html('');
        modal.find('#health-content-img-show .new').html('');//可能存在bug
        modal.find("#health-shop-img-show").html(`<div>图片预览</div>`);
        //根据type判断是2修改还是1新增
        if(type == 1){
            modal.find('#healthBusinessModalLabel').text('新增健康服务商家');
        }else if(type == 2){
            modal.find('#healthBusinessModalLabel').text('修改健康服务商家信息');
            var businessId = btnThis.data('id');
            modal.find('#health-businessId').val(businessId);
            var businessInfo = '';
            for(var i in healthList){
                if(healthList[i].id == businessId){
                    businessInfo = healthList[i]
                }
            }
            // console.log(businessInfo);
            shopName.val(businessInfo.shop_name);
            address.val(businessInfo.address);
            phone.val(businessInfo.phone);
            lat.val(businessInfo.lat);
            lng.val(businessInfo.lng);
            shopDesc.val(businessInfo.content);
            healthImgs = businessInfo.head_banner;
            shopImg.val(businessInfo.shop_img);
            modal.find('#health-shop-img-show').html(`<img src="${businessInfo.shop_img}" />`);
            var head_banner = businessInfo.head_banner;
            // console.log(head_banner);
            var html = '';
            for(var j in head_banner){
                html+= `
                    <div class="content-old-img-item">
                        <img src="${head_banner[j].banner_img}" alt="">
                        <div class="del themeColor">删 除</div>
                     </div>
                `
            }
            modal.find('#health-content-img-show  .old').html(html);
            obj.each(function(){
                var that = $(this);
                for(var k in businessInfo.class_id){
                    if(that.val() == businessInfo.class_id[k].class_id){
                        // console.log(that.val());
                        that.prop('checked',true);
                    }
                }
            })

        }

    })
    //获取地址
    $('#healthShopAddress').on('input propertychange',function(){
        var keyword = $(this).val();
        // console.log(keyword == '');
        var region = '天津';
        if(keyword != ''){
            getAjax(`${global.apiUrl}/Api/Url/ceshi`,res =>{
                // console.log(res);
                if(res.status == 0){
                    var html = '';
                    for(var i in res.data){
                        html += `
                        <div class="address-list-item themeColor">
                            <div class="address-title">${res.data[i].title}</div>
                            <div class="address-address">${res.data[i].address}</div>
                            <input type="hidden" class="lat" value="${res.data[i].location.lat}">
                            <input type="hidden" class="lng" value="${res.data[i].location.lng}">
                        </div>
                    `
                    }
                    $('#healthBusinessModal .address-list').html(html);
                }
            },{
                keyword:keyword,
                key:'6VNBZ-2YSC3-UAK3W-YDOS4-QLWCT-OWBXM',
                region:region
            })
        }else{
            $('#healthBusinessModal .address-list').html('');
        }

    });
    $('#healthBusinessModal .address-list').on('click','.address-list-item',function(){
        var address = $(this).find('.address-address').text();
        var title = $(this).find('.address-title').text();
        var lat = $(this).find('.lat').val();
        var lng = $(this).find('.lng').val();
        $('#healthBusinessModal .address-list').html('');
        $('#healthShopAddress').val(`${title} (${address})`)
        $('#health-shop-address-lat').val(lat)
        $('#health-shop-address-lng').val(lng)
    })
    /** 添加 修改 **/
    $('#addHealthShop').on('click',function(){

        //获取选择的类别
        var obj = document.getElementsByClassName("health-class-checked");
        var check_class = new Array();
        for(k in obj){
            if(obj[k].checked){
                var objItem = {"class_id":obj[k].value}
                check_class.push(objItem);
            }
        }
        console.log(check_class);
        var subContent = [];
        for(var i in check_class){
            for(var j in healthServiceClass){
                if(check_class[i].class_id == healthServiceClass[j].id){
                    subContent.push(healthServiceClass[j].class_name)
                }
            }
        }
        subContent = subContent.toString();
        //获取名称
        var shopName = $('#healthShopName').val();
        //地址及其lat  lng
        var address = $('#healthShopAddress').val();
        var lat = $('#health-shop-address-lat').val();
        var lng = $('#health-shop-address-lng').val();
        //商家电话
        var phone = $('#healthShopPhone').val();
        //获取缩略图
        var shopImg = $('#health-shop-img-url').val();
        //获取商家图集
        var headBanner = JSON.stringify(healthImgs);
        //商家描述
        var shopDesc = $('#health-shopDesc').val();
        console.log(check_class,shopName,shopImg,address,lat,lng,phone,headBanner,subContent,shopDesc);
        //数据
        if(shopName == ''||phone == ''||address==''||shopImg==''||subContent==''||headBanner==''||shopDesc==""){
            alert('请将信息填写完整！')
        }else{
            var type = $("#health-upType").val();
            console.log('type:',type);
            var id = $("#health-businessId").val();
            var text = '';
            if(type == 2){
                // id = $(this).data('id');
                text = '商家信息，修改成功！';
            }else if(type == 1){
                text = '新的商家，添加成功！';
            }
            console.log('businessId',id);
            var data = {
                "shop_name":shopName,
                "phone":phone,
                "address":address,
                "shop_img":shopImg,
                "sub_content":subContent,
                "head_banner":headBanner,
                "content":shopDesc,
                "community_id":global.community_id,
                "lat":lat,
                "lng":lng,
                "id":id
            }
            data = JSON.stringify(data);
            console.log(data);
            check_class = JSON.stringify(check_class);
            $.ajax({
                url:`${global.apiUrl}/admin_operation_community_service_up_home_shop`,
                type:'GET',
                data:{
                    type:type,
                    pro:data,
                    all_class:check_class
                    // shop_id:id
                },
                success(res){
                    console.log(res);
                    if(res == 1){
                        alert(text);
                        $('#healthBusinessModal').modal('hide');
                        getHealthBusiness(healthPageNo,showNum);
                    }
                },
                error(res){
                    console.log(res);
                }
            })

        }


    })
    /** 删除 **/
    $('#health-service-business').on('click','.business-delete',function(){
        var businessId = $(this).data('id');
        console.log(businessId);
        var f = confirm('是否删除该商户');
        if(f){
            getAjax(`${global.apiUrl}/admin_operation_community_service_up_home_shop`,function(res){
                console.log(res);
                if(res == 1){
                    alert('商户删除成功！');
                    getHealthBusiness(healthPageNo,showNum);
                }
            },{
                type:3,
                shop_id:businessId
            })
        }

    })

    /***
     * 健康服务 end
     ***/



    /***
     *  预售超市  begin
     ***/
    var advanceSaleList = '';
    function getAdvanceSaleList(){
        getAjax(`${global.apiUrl}/get_community_service_banner`,res=>{
            // console.log(res);
            var html = '';
            advanceSaleList = res;
            for(var i in res){
                html += `
                    <tr>
                        <td>${res[i].id}</td>
                        <td class="advance-sale-banner">
                            <img src="${res[i].banner_img}" alt="">
                        </td>
                        <td class="advance-sale-content">
                            <img src="${res[i].content_img}" alt="">
                        </td>
                        <td class="control-td themeColor">
                            <span class="business-reset" data-id="${res[i].id}" data-type="2" data-target="#advanceSaleModal" data-toggle="modal">修改</span> 
                            <span class="business-delete" style="margin-left: 15px" data-id="${res[i].id}">删除</span></td>
                        </td>
                    </tr>
                `
            }
            $('#advance-sale-list').html(html)
        },{
            community_id:global.community_id,
            limit:2
        })
    }
    getAdvanceSaleList();
    $('#advanceSaleModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        console.log(type);
        modal.find('#advanceSaleUptype').val(type);
        modal.find('#advanceSaleId').val('');
        modal.find("#advanceSaleContentImage").html(`<div>图片预览</div>`);
        modal.find("#advanceSaleBannerImage").html(`<div>图片预览</div>`);
        //根据type判断是2修改还是1新增
        if(type == 1){
            modal.find('#advanceSaleModalLabel').text('新增热门内容');
        }else if(type == 2){
            modal.find('#advanceSaleModalLabel').text('修改热门内容');
            var businessId = btnThis.data('id');
            modal.find('#advanceSaleId').val(businessId);
            var businessInfo = '';
            for(var i in advanceSaleList){
                if(advanceSaleList[i].id == businessId){
                    businessInfo = advanceSaleList[i]
                }
            }
            modal.find('#advanceSaleContentImage').html(`<img src="${businessInfo.content_img}" />`);
            modal.find('#advanceSaleContentImgUrl').val(businessInfo.content_img);
            modal.find('#advanceSaleBannerImage').html(`<img src="${businessInfo.banner_img}" />`);
            modal.find('#advanceSaleBannerImgUrl').val(businessInfo.banner_img);
        }
    })
    function setAdvanceSaleContentImg(res){
        document.getElementById('advanceSaleContentImgUrl').value = res;
    }
    function setAdvanceSaleBannerImg(res){
        document.getElementById('advanceSaleBannerImgUrl').value = res;
    }
    imgUpload('advanceSaleContentInput','advanceSaleContentImage',setAdvanceSaleContentImg);
    imgUpload('advanceSaleBannerInput','advanceSaleBannerImage',setAdvanceSaleBannerImg);
    $('#uploadAdvanceSaleImg').on('click',function(){
        var id = $('#advanceSaleId').val();
        var type = $('#advanceSaleUptype').val();
        var banner_img = $('#advanceSaleBannerImgUrl').val();
        var content_img = $('#advanceSaleContentImgUrl').val();
        var date = new Date();
        var year = date.getFullYear();
        var month = (date.getMonth()+1)>10?date.getMonth()+1:'0'+(date.getMonth()+1);
        var day = date.getDate()>10?date.getDate():'0'+date.getDate();
        var hour = date.getHours();
        var m = date.getMinutes();
        var release_time = year+'-'+month+'-'+day+' '+hour+":"+m;
        // var release_time = ;
        var data = {
            id:id,
            banner_img:banner_img,
            content_img:content_img,
            release_time:release_time,
            community_id:global.community_id
        };
        data = JSON.stringify(data)
        console.log(id, type, banner_img, content_img);
        if(banner_img == ''||content_img == ""){
            alert('请选择图片后上传！')
        }else{
            getAjax(`${global.apiUrl}/admin_operation_community_banner`,res=>{
                console.log(res);
                if(res == 1){
                    alert('上传成功！');
                    $('#advanceSaleModal').modal('hide');
                    getAdvanceSaleList();
                }
            },{
                type:type,
                pro:data
            })
        }
    })
    $('#advance-sale-list').on('click','.business-delete',function(){
        var id = $(this).data('id');
        var f = confirm('是否删除该信息？');
        if(f){
            getAjax(`${global.apiUrl}/admin_operation_community_banner`,res=>{
                console.log(res);
                if(res == 1){
                    alert('信息已删除');
                    getAdvanceSaleList();
                }
            },{
                type:3,
                id:id
            })
        }

    })

    /***
     *  预售超市  end
     ***/



    /***
     *  线上药店 begin
     * ***/
    /** 获取药店列表 **/
    var pharmacyPage = 1;
    var pharmacyList = '';
    function getPharmacyList(p,showNum,like){
        getAjax(`${global.apiUrl}/get_community_service_pharmacy`,function(res){
            // console.log(res);
            if(res.list.length == 0){
                console.log('i');
                $("#pharmacy-page").paging({
                    pageNo:1,
                    totalPage: 0, //总页数
                    totalSize: 0,
                    callback: function(num) {
                        getPharmacyList(num,showNum)
                    }
                });
                var html = `
                        <tr>
                            <td colspan="5" align="center">暂无药店</td>
                        </tr>`
                $('#pharmacy-list').html(html);
            }else{
                $("#pharmacy-page").paging({
                    pageNo:p,
                    totalPage: Math.ceil(res.count/showNum), //res.all总页数 模拟数据10
                    totalSize: res.count,
                    callback: function(num) {
                        getPharmacyList(num,showNum)
                        pharmacyPage = num
                    }
                });
                var html = '';
                var list = res.list;
                pharmacyList = res.list;
                for(var i in list){
                    html += `
                    <tr>
                        <td class="shop-img">
                        <img src="${list[i].img}" alt="">
                        </td>
                        <td>${list[i].shop_name}</td>
                        <td>${list[i].phone}</td>
                        <td>${list[i].address}</td>
                        <td class="control-td themeColor">
                            <span class="business-reset" data-id="${list[i].id}" data-type="2" data-target="#onlinePharmacyModal" data-toggle="modal">修改</span> 
                            <span class="business-delete" style="margin-left: 15px" data-id="${list[i].id}">删除</span>
                        </td>
                        
                    </tr>
                `
                }
                $('#pharmacy-list').html(html);
            }

        },{
            p:p,
            num:showNum,
            community_id:global.community_id,
            like:like
        })
    }
    getPharmacyList(pharmacyPage,showNum);

    function setPharmacyImgUrl(res){
        document.getElementById('pharmacy-img-url').value = res;
    }
     //商家展示图片
    imgUpload('pharmacy-img-select','pharmacy-img-show',setPharmacyImgUrl);
    var pharmacyImgs = [];
    var parchmacyImgurl;
    function setPharmacyContentImgUrl(res){
        if(res.length != 0){
            parchmacyImgurl = {
                banner_img:res
            };
            pharmacyImgs.push(parchmacyImgurl);
            $('#pharmacy-upload-content-img').css('display','none');
        }

    }
    var pharmacyImgArr = imgUploadShow('pharmacy-content-img-select','pharmacy-content-img-show');
    //新图删除
    $('#pharmacy-content-img-show').on('click','.cancle',function(){
        var index = $(this).parent().index();
        pharmacyImgs.splice(index,1);
        var contentImgList = document.getElementById('pharmacy-content-img-show');
        var contentNewImgList = contentImgList.getElementsByClassName('new')[0];
        var contentImgItem = contentNewImgList.getElementsByClassName('content-img-item');
        contentNewImgList.removeChild(contentImgItem[index])

    })
    //旧图删除
    $('#pharmacy-content-img-show').on('click','.del',function(){
        var index = $(this).parent().index();
        pharmacyImgs.splice(index,1);
        var contentImgList = document.getElementById('pharmacy-content-img-show');
        var contentOldImgList = contentImgList.getElementsByClassName('old')[0];
        var contentImgItem = contentOldImgList.getElementsByClassName('content-old-img-item');
        contentOldImgList.removeChild(contentImgItem[index])
    })
    $('#pharmacy-upload-content-img').on('click',function(){
        allImgUpload(pharmacyImgArr,setPharmacyContentImgUrl);
    });
    $('#onlinePharmacyModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        modal.find('#pharmacy-upType').val(type);
        modal.find('#pharmacy-upload-content-img').css('display','block');
        modal.find('#pharmacyId').val('');
        // console.log(type);
        var pharmacyName = modal.find('#pharmacyName');
        pharmacyName.val('');
        var pharmacyPhone = modal.find("#pharmacyPhone");
        pharmacyPhone.val('');
        var pharmacyAddress = modal.find("#pharmacyAddress");
        pharmacyAddress.val('');
        var pharmacyLat = modal.find('#pharmacy-address-lat');
        pharmacyLat.val('');
        var pharmacyLng = modal.find('#pharmacy-address-lng');
        pharmacyLng.val('');
        var pharmacyImg = modal.find('#pharmacy-img-url');
        pharmacyImg.val('');
        //商家描述
        var pharmacyDesc = modal.find('#pharmacyDesc');
        pharmacyDesc.val('');
        //分类
        // var obj = $(".class-checked");
        // obj.attr('checked',false);
        modal.find('#pharmacy-content-img-show .old').html('');
        modal.find('#pharmacy-content-img-show .new').html('');//可能存在bug
        modal.find("#pharmacy-img-show").html(`<div>图片预览</div>`);
        //根据type判断是2修改还是1新增
        if(type == 1){
            modal.find('#pharmacyModalLabel').text('新增药店');
        }else if(type == 2){
            modal.find('#pharmacyModalLabel').text('修改药店信息');
            var pharmacyId = btnThis.data('id');
            modal.find('#pharmacyId').val(pharmacyId);
            var pharmacyInfo = '';
            for(var i in pharmacyList){
                if(pharmacyList[i].id == pharmacyId){
                    pharmacyInfo = pharmacyList[i]
                }
            }
            // console.log(pharmacyInfo);
            pharmacyName.val(pharmacyInfo.shop_name);
            pharmacyAddress.val(pharmacyInfo.address);
            pharmacyPhone.val(pharmacyInfo.phone);
            pharmacyLat.val(pharmacyInfo.lat);
            pharmacyLng.val(pharmacyInfo.lng);
            pharmacyDesc.val(pharmacyInfo.content);
            pharmacyImgs = pharmacyInfo.head_banner;
            pharmacyImg.val(pharmacyInfo.img);
            modal.find('#pharmacy-img-show').html(`<img src="${pharmacyInfo.img}" />`);
            var head_banner = pharmacyInfo.head_banner;
            // console.log(head_banner);
            var html = '';
            for(var j in head_banner){
                html+= `
                    <div class="content-old-img-item">
                        <img src="${head_banner[j].banner_img}" alt="">
                        <div class="del themeColor">删 除</div>
                     </div>
                `
            }
            modal.find('#pharmacy-content-img-show  .old').html(html);
        }

    })
    //获取地址
    $('#pharmacyAddress').on('input propertychange',function(){
        var keyword = $(this).val();
        // console.log(keyword == '');
        var region = '天津';
        if(keyword != ''){
            getAjax(`${global.apiUrl}/Api/Url/ceshi`,res =>{
                // console.log(res);
                if(res.status == 0){
                    var html = '';
                    for(var i in res.data){
                        html += `
                        <div class="address-list-item themeColor">
                            <div class="address-title">${res.data[i].title}</div>
                            <div class="address-address">${res.data[i].address}</div>
                            <input type="hidden" class="lat" value="${res.data[i].location.lat}">
                            <input type="hidden" class="lng" value="${res.data[i].location.lng}">
                        </div>
                    `
                    }
                    $('#onlinePharmacyModal .address-list').html(html);
                }
            },{
                keyword:keyword,
                key:'6VNBZ-2YSC3-UAK3W-YDOS4-QLWCT-OWBXM',
                region:region
            })
        }else{
            $('#onlinePharmacyModal .address-list').html('');
        }

    });
    $('#onlinePharmacyModal .address-list').on('click','.address-list-item',function(){
        var address = $(this).find('.address-address').text();
        var title = $(this).find('.address-title').text();
        var lat = $(this).find('.lat').val();
        var lng = $(this).find('.lng').val();
        $('.address-list').html('');
        $('#pharmacyAddress').val(`${title} (${address})`)
        $('#pharmacy-address-lat').val(lat)
        $('#pharmacy-address-lng').val(lng)
    })
    /** 添加 修改 **/
    $('#addPharmacy').on('click',function(){
        //获取名称
        var pharmacyName = $('#pharmacyName').val();
        //地址及其lat  lng
        var address = $('#pharmacyAddress').val();
        var lat = $('#pharmacy-address-lat').val();
        var lng = $('#pharmacy-address-lng').val();
        //商家电话
        var phone = $('#pharmacyPhone').val();
        //获取缩略图
        var pharmacyImg = $('#pharmacy-img-url').val();
        //获取商家图集
        var headBanner = JSON.stringify(pharmacyImgs);
        //商家描述
        var pharmacyDesc = $('#pharmacyDesc').val();
        // console.log(check_class,shopName,shopImg,address,lat,lng,phone,headBanner,subContent,shopDesc);
        //数据
        if(pharmacyName == ''||phone == ''||address==''||pharmacyImg==''||headBanner==''||pharmacyDesc==""){
            alert('请将信息填写完整！')
        }else{
            var type = $("#pharmacy-upType").val();
            console.log('type:',type);
            var id = $("#pharmacyId").val();
            var text = '';
            if(type == 2){
                // id = $(this).data('id');
                text = '商家信息，修改成功！';
            }else if(type == 1){
                text = '新的商家，添加成功！';
            }
            console.log('pharmacyId',id);
            var data = {
                "id":id,
                "shop_name":pharmacyName,
                "phone":phone,
                "address":address,
                "img":pharmacyImg,
                "head_banner":headBanner,
                "content":pharmacyDesc,
                "community_id":global.community_id,
                "lat":lat,
                "lng":lng
            }
            data = JSON.stringify(data);
            // console.log(data);
            // check_class = JSON.stringify(check_class);
            $.ajax({
                url:`${global.apiUrl}/admin_operation_community_service_pharmacy`,
                type:'GET',
                data:{
                    type:type,
                    pro:data
                },
                success(res){
                    // console.log(res);
                    if(res == 1){
                        alert(text);
                        $('#onlinePharmacyModal').modal('hide');
                        getPharmacyList(pharmacyPage,showNum);
                    }
                },
                error(res){
                    console.log(res);
                }
            })

        }


    })
    /** 删除 **/
    $('#pharmacy-list').on('click','.business-delete',function(){
        var businessId = $(this).data('id');
        var f = confirm('是否删除该商户');
        if(f){
            getAjax(`${global.apiUrl}/admin_operation_community_service_pharmacy`,function(res){
                console.log(res);
                if(res == 1){
                    alert('商户删除成功！');
                    getPharmacyList(pharmacyPage,showNum);
                }
            },{
                type:3,
                id:businessId
            })
        }

    })
    //搜索
    $('#pharmacy-search-btn').on('click',function(){
        var $keyword = $('#pharmacy-search-content').val();
        getPharmacyList(pharmacyPage,showNum,$keyword);
    })


    /***
     *  线上药店 end
     * ***/
});
/****
*     特膳厨房
 ***/
$(document).ready(function(){
    //获取厨房主体
    var kitchenInfo = ''
    function getKitchen(){
        getAjax(`${global.apiUrl}/get_community_service_kitchen`,res=>{
            console.log(res);
            kitchenInfo = res;
            var html = '';
            if(res){
                // console.log(1);
                $('#addKitchen').css('display','none');
                html = `
                    <tr>
                        <td>${res.name}</td>
                        <td>${res.user_name}</td>
                        <td class="themeColor cursor" style="width: 200px">
                            <span data-id="${res.id}" data-type="2" data-status='0' data-toggle="modal" data-target="#kitchenModal">修改信息</span>
                            <span style="margin-left: 10px" data-id="${res.id}" data-type="2" data-status='1' data-toggle="modal" data-target="#kitchenModal" type="2">密码重置</span>
                        </td>
                    </tr>
                `
                $('#kitchenList').html(html);
            }
        },{
            community_id:global.community_id
        })
    }
    getKitchen();
    //模态框弹出
    $('#kitchenModal').on('show.bs.modal',function(event){
        var modal = $(this);
        var btnThis = $(event.relatedTarget);
        var type = btnThis.data('type');
        modal.find('#kitchenType').val(type);
        modal.find('#kitchenStatus').val('');
        modal.find('#kitchenName').val('');
        modal.find('#kitchenUserName').val('');
        modal.find('#kitchenPwd').val('');
        modal.find('#kitchenId').val('');
        modal.find('#kitchenPhone').val('');
        modal.find('#kitchenAlaLev').val('');
        modal.find('#kitchenShiLev').val('');
        modal.find('#kitchenQuLev').val('');
        var text = '';
        if(type == 1){
            text = '添加厨房';
            modal.find('#kitchenStatus').val('3');
        }else if(type == 2){
            var id = btnThis.data('id');
            var status = btnThis.data('status');
            console.log(status);
            text = '修改厨房信息';
            modal.find('#kitchenName').val(kitchenInfo.name);
            modal.find('#kitchenUserName').val(kitchenInfo.user_name);
            modal.find('#kitchenAlaLev').val(kitchenInfo.als_lv*100);
            modal.find('#kitchenShiLev').val(kitchenInfo.shi_lv*100);
            modal.find('#kitchenQuLev').val(kitchenInfo.qu_lv*100);
            modal.find('#kitchenPhone').val(kitchenInfo.phone);
            modal.find('#kitchenPwd').attr('placeholder','请输入新的密码');
            modal.find('#kitchenId').val(id);
            modal.find('#kitchenStatus').val(status);
            modal.find('#kitchenUnameBox').css('display','block');
            modal.find('#kitchenNameBox').css('display','block');
            modal.find('#kitchenPwdBox').css('display','block');
            modal.find('#kitchenPhoneBox').css('display','block');
            if(status == 0){
                modal.find('#kitchenPwdBox').css('display','none');
                modal.find('#kitchenUnameBox').css('display','none');
                // modal.find('#kitchenPhoneBox').css('display','none');
            }else if(status == 1){
                modal.find('#kitchenUnameBox').css('display','none');
                modal.find('#kitchenNameBox').css('display','none');
                modal.find('#kitchenPhoneBox').css('display','none');
                modal.find('#kitchenAlaLevBox').css('display','none');
                modal.find('#kitchenQuLevBox').css('display','none');
                modal.find('#kitchenShiLevBox').css('display','none');
            }else if(status == 3){

            }
        }
        modal.find('#kitchenModalLabel').text(text);
    })
    //添加修改
    $('#addkitchenBtn').on('click',function(){
        // console.log(1);
        var name = $('#kitchenName').val();
        var user_name = $('#kitchenUserName').val();
        var user_pwd = $('#kitchenPwd').val();
        var type = $('#kitchenType').val();
        var id = $('#kitchenId').val();
        var phone = $('#kitchenPhone').val();
        var shi_lv = $('#kitchenShiLev').val();
        var qu_lv = $('#kitchenQuLev').val();
        var als_lv = $('#kitchenAlaLev').val();
        //status 0 为修改信息  1 添加 或 重置密码
        var status = $('#kitchenStatus').val();
        console.log(status,kitchenInfo.login_content.id);
        if(status==0||status == 3){
            if(status == 0){
                var pro = {
                    id:id,
                    community_id:global.community_id,
                    name:name,
                    shi_lv:shi_lv/100,
                    qu_lv:qu_lv/100,
                    als_lv:als_lv/100,
                    phone:phone
                }

            }else if(status == 3){
                var pro = {
                    id:id,
                    community_id:global.community_id,
                    name:name,
                    user_name:user_name,
                    user_pwd:user_pwd,
                    shi_lv:shi_lv/100,
                    qu_lv:qu_lv/100,
                    als_lv:als_lv/100,
                    phone:phone
                }
            }

            //添加user_content
            var user_content = {
                user_name:user_name,
                user_pwd:user_pwd,
                community_id:global.community_id
            }
            user_content = JSON.stringify(user_content);
            pro = JSON.stringify(pro);
            console.log(pro, user_content);
            getAjax(`${global.apiUrl}/admin_operation_community_service_kitchen`,res=>{
                console.log(res);
                if(res == 1){
                    alert('信息上传成功！')
                    getKitchen();
                    $('#kitchenModal').modal('hide')
                }
            },{
                type:type,
                pro:pro,
                phone:phone,
                user_content:user_content
            })

        }
        if(status == 1){
            getAjax(`${global.apiUrl}/Api/Alladmin/yes_user_pwd`,res=>{
                console.log(res);
                if(res==1){
                    alert('密码重置成功！');
                    $('#kitchenModal').modal('hide');
                }
            },{
                user_pwd:user_pwd,
                id:kitchenInfo.login_content.id
            })
        }

    })
})
